<?php use_javascript(plugin_web_path('orangehrmTLUPimPlugin', 'js/viewEmploymentContractList')); ?>

<?php $hasEmploymentContracts = count($employmentContracts); ?>

<?php

function getSortClass($column, $sortField, $sortOrder)
{

    if (isset($sortField) && isset($sortOrder) && $column == $sortField) {
        $class = ' headerSort';
        $class .= ($sortOrder == 'ASC') ? 'Up' : 'Down';
        return $class;
    }

    return '';

}

?>

<div class="box pimPane">

    <?php
    include_partial('pim/pimLeftMenu', array('empNumber' => $empNumber));
    ?>

    <a name="employmentContracts"></a>

    <?php if ($employmentContractPermissions->canRead()) : ?>

        <div id="employmentContractList" class="miniList">
            <div class="head">
                <h1><?php echo __('Employment Contracts'); ?></h1>
            </div>
            <div class="inner">

                <?php include_partial('global/flash_messages', array('prefix' => 'employmentcontract')); ?>

                <form name="frmEmpDelEmploymentContracts" id="frmEmpDelEmploymentContracts" method="post"
                      action="<?php echo url_for('tlupim/deleteEmploymentContracts'); ?>">
                    <input type="hidden" name="empNumber" value="<?php echo $empNumber; ?>"/>

                    <p id="employmentContractActions">
                        <?php if ($employmentContractPermissions->canCreate()) : ?>
                            <input type="button" class="addbutton" id="btnAddEmploymentContract"
                                   value="<?php echo __("Add"); ?>"/>
                        <?php endif; // $employmentContractPermissions->canCreate() ?>
                        <?php if ($employmentContractPermissions->canDelete() && $hasEmploymentContracts) : ?>
                            <input type="button" class="delete" id="btnDeleteEmploymentContract"
                                   value="<?php echo __("Delete"); ?>" data-toggle="modal"
                                   data-target="#deleteConfModal"/>
                        <?php endif; // $employmentContractPermissions->canDelete() && $hasEmploymentContracts ?>
                    </p>

                    <table id="tblEmploymentContracts" cellpadding="0" cellspacing="0" width="100%"
                           class="table tablesorter">
                        <thead>
                        <tr>
                            <th class="check" style="width:2%"><input type="checkbox" id="checkAll" class="checkbox"/>
                            </th>
                            <th class="fieldEmpContractNo header<?php echo getSortClass('empContractNo', $sortField, $sortOrder); ?>"
                                style="width:15%">
                                <?php echo $sorter->sortLink('empContractNo', __("Employment Contract Number"), '@employmentContract_list', array(), "empNumber=$empNumber", ESC_RAW); ?>
                            </th>
                            <th class="fieldEmploymentContractType"
                                style="width:38%"><?php echo __("Employment Contract Type") ?></th>
                            <th class="fieldDuration header<?php echo getSortClass('duration', $sortField, $sortOrder); ?>"
                                style="width:20%">
                                <?php echo $sorter->sortLink('duration', __("Employment Contract Duration"), '@employmentContract_list', array(), "empNumber=$empNumber", ESC_RAW); ?>
                            </th>
                            <th class="fieldStartDate header<?php echo getSortClass('start_date', $sortField, $sortOrder); ?>"
                                style="width:20%">
                                <?php echo $sorter->sortLink('start_date', __("Employment Contract Start Date"), '@employmentContract_list', array(), "empNumber=$empNumber", ESC_RAW); ?>
                            </th>
                            <th width="5%"></th>
                        </tr>
                        </thead>
                        <tbody>

                        <?php
                        $disabled = ($employmentContractPermissions->canDelete()) ? "" : 'disabled="disabled"';
                        $row = 0;
                        ?>

                        <?php foreach ($employmentContracts as $employmentContract) : ?>
                            <?php $cssClass = ($row % 2) ? 'even' : 'odd'; ?>

                            <tr class="<?php echo $cssClass; ?>">

                                <td class="check">
                                    <input type="checkbox" <?php echo $disabled; ?> class="checkbox"
                                           name="chkListRecord[]" value="<?php echo $employmentContract->id; ?>"/>
                                </td>
                                <td class="tdEmpContractNo tdValue">
                                    <?php echo $employmentContract->empContractNo; ?>
                                </td>
                                <td class="tdEmploymentContractType tdValue">
                                    <?php echo $employmentContractTypes[$employmentContract->employment_contract_type_id]; ?>
                                </td>
                                <td class="tdDuration tdValue">
                                    <?php echo $employmentContract->duration; ?>
                                </td>
                                <td class="tdStartDate tdValue">
                                    <?php echo set_datepicker_date_format($employmentContract->start_date); ?>
                                </td>
                                <?php if ($employmentContractPermissions->canUpdate()) : ?>
                                    <td>
                                        <a href="#" class="editLink"><?php echo __("Edit"); ?></a>
                                    </td>
                                <?php else: ?>
                                    <td>
                                    </td>
                                <?php endif; ?>
                            </tr>

                            <?php $row++; ?>
                        <?php endforeach; ?>

                        <?php if (count($employmentContracts) == 0) : ?>
                            <tr>
                                <td colspan="6">
                                    <?php echo __(TopLevelMessages::NO_RECORDS_FOUND); ?>
                                </td>
                            </tr>
                        <?php endif; ?>

                        </tbody>
                    </table>

                </form>

            </div>
        </div> <!-- employmentContractList -->

    <?php endif; // $employmentContractPermissions->canRead() ?>
</div>

<?php include_partial('global/delete_confirmation'); ?>

<script type="text/javascript">
    //<![CDATA[

    var empNumber = '<?php echo $empNumber; ?>';
    var employmentContracts = <?php echo $hasEmploymentContracts;?>;
    var addEmploymentContractUrl = '<?php echo url_for('tlupim/saveEmploymentContract?empNumber=' . $empNumber); ?>';
    var editEmploymentContractUrlSegment = '<?php echo url_for('tlupim/saveEmploymentContract?empNumber=' . $empNumber . '&employmentContractId='); ?>';

    //]]>
</script>